package com.hut.bms.interceptor;

import com.hut.bms.Constant.Constants;
import com.hut.bms.model.Result;
import com.hut.bms.model.UserInfo;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
@Component
public class LoginIntercreptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        UserInfo loginUserInfo = (UserInfo) session.getAttribute(Constants.USER_SESSION_KEY);
        if (loginUserInfo == null || loginUserInfo.getId() <= 0) {
            //用户未登录
            response.setStatus(401);
            return false;
        }
        return true;
    }
}
